from urllib.parse import urlparse, unquote

import os

def extract_filename_from_url(url):
    # 解析URL
    parsed_url = urlparse(url)
    # 获取路径部分并解码任何URL编码的字符
    path = unquote(parsed_url.path)
    # 使用正则表达式找到最后一个斜杠之后的所有内容
    filename = path.split('/')[-1]
    return filename

def travel_file(folder_path, filter_func=None):
    for dirpath, dirnames, filenames in os.walk(folder_path):
        print(f"checking {dirpath}...")
        for filename in filenames:
            if filter_func is None:
                yield dirpath, filename
            elif filter_func(dirpath, filename):
                yield dirpath, filename